package com.kunlun.system.model;

import com.kunlun.common.model.monitor.CpuInfoModel;
import com.kunlun.common.model.monitor.DiskInfoModel;
import com.kunlun.common.model.monitor.JvmInfoModel;
import com.kunlun.common.model.monitor.MemoryInfoModel;
import com.kunlun.common.model.monitor.NetworkInfoModel;
import com.kunlun.common.model.monitor.SystemDataModel;
import com.kunlun.common.model.monitor.SystemInfoModel;
import com.kunlun.common.utils.CommonUtil;
import org.springframework.util.ObjectUtils;

import java.util.Date;
import java.util.List;

/**
 * 系统监控数据模型
 */
public class SystemInstanceModel {

    // 主键ID
    private String id;

    // t_system_machine表主键
    private String machineId;

    // 计算机名
    private String computerName;

    // 系统名
    private String systemName;

    // 系统架构
    private String systemArchitecture;

    // 系统userDir
    private String userDirectory;

    // JVM总内存
    private String jvmTotalMemory;

    // JVM最大内存
    private String jvmMaxMemory;

    // JVM空闲内存
    private String jvmFreeMemory;

    // JVM已使用内存
    private String jvmUsedMemory;

    // JVM内存使用率
    private String jvmUsedPercent;

    // JVM启动时间
    private Date jvmStartTime;

    // JVM运行时间
    private long jvmUpTime;

    // JDK名
    private String jdkName;

    // JDK HOME
    private String jdkHome;

    // JDK版本
    private String jdkVersion;

    // 每秒钟接收的数据包
    private int netReceiveDataCount;

    // 每秒钟发送的数据包
    private int netSendDataCount;

    // 每秒钟接收的KB数
    private int netReceiveKbCount;

    // 每秒钟发送的KB数
    private int netSendKbCount;

    private Date createTime;

    private Date modifiedTime;

    public SystemInstanceModel() {
    }

    public SystemInstanceModel(SystemDataModel systemDataModel) {
        this.id = CommonUtil.generateUUID();
        JvmInfoModel jvmInfoModel = systemDataModel.getJvmInfoModel();
        SystemInfoModel systemInfoModel = systemDataModel.getSystemInfoModel();
        NetworkInfoModel networkInfoModel = systemDataModel.getNetworkInfoModel();
        if (!ObjectUtils.isEmpty(jvmInfoModel)) {
            this.jdkName = jvmInfoModel.getJdkName();
            this.jdkHome = jvmInfoModel.getJdkHome();
            this.jdkVersion = jvmInfoModel.getJdkVersion();
            this.jvmTotalMemory = jvmInfoModel.getJvmTotalMemory();
            this.jvmMaxMemory = jvmInfoModel.getMaxMemory();
            this.jvmFreeMemory = jvmInfoModel.getFreeMemory();
            this.jvmUsedMemory = jvmInfoModel.getUsedMemory();
            this.jvmUsedPercent = String.valueOf(jvmInfoModel.getUsePercent());
            this.jvmStartTime = new Date(jvmInfoModel.getStartTime());
            this.jvmUpTime = jvmInfoModel.getUptime();
        }
        if (!ObjectUtils.isEmpty(systemInfoModel)) {
            this.computerName = systemInfoModel.getName();
            this.systemName = systemInfoModel.getOsName();
            this.systemArchitecture = systemInfoModel.getOsArch();
            this.userDirectory = systemInfoModel.getUserDir();
        }
        if (!ObjectUtils.isEmpty(networkInfoModel)) {
            this.netReceiveDataCount = Integer.valueOf(networkInfoModel.getRxpck());
            this.netSendDataCount = Integer.valueOf(networkInfoModel.getTxpck());
            this.netReceiveKbCount = Integer.valueOf(networkInfoModel.getRxbyt());
            this.netSendKbCount = Integer.valueOf(networkInfoModel.getTxbyt());
        }
        this.createTime = new Date();
        this.modifiedTime = new Date();
    }

    public String getId() {
        return id;
    }

    public String getMachineId() {
        return machineId;
    }

    public void setMachineId(String machineId) {
        this.machineId = machineId;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getComputerName() {
        return computerName;
    }

    public void setComputerName(String computerName) {
        this.computerName = computerName;
    }

    public String getSystemName() {
        return systemName;
    }

    public void setSystemName(String systemName) {
        this.systemName = systemName;
    }

    public String getSystemArchitecture() {
        return systemArchitecture;
    }

    public void setSystemArchitecture(String systemArchitecture) {
        this.systemArchitecture = systemArchitecture;
    }

    public String getUserDirectory() {
        return userDirectory;
    }

    public void setUserDirectory(String userDirectory) {
        this.userDirectory = userDirectory;
    }

    public String getJvmTotalMemory() {
        return jvmTotalMemory;
    }

    public void setJvmTotalMemory(String jvmTotalMemory) {
        this.jvmTotalMemory = jvmTotalMemory;
    }

    public String getJvmMaxMemory() {
        return jvmMaxMemory;
    }

    public void setJvmMaxMemory(String jvmMaxMemory) {
        this.jvmMaxMemory = jvmMaxMemory;
    }

    public String getJvmFreeMemory() {
        return jvmFreeMemory;
    }

    public void setJvmFreeMemory(String jvmFreeMemory) {
        this.jvmFreeMemory = jvmFreeMemory;
    }

    public String getJvmUsedMemory() {
        return jvmUsedMemory;
    }

    public void setJvmUsedMemory(String jvmUsedMemory) {
        this.jvmUsedMemory = jvmUsedMemory;
    }

    public String getJvmUsedPercent() {
        return jvmUsedPercent;
    }

    public void setJvmUsedPercent(String jvmUsedPercent) {
        this.jvmUsedPercent = jvmUsedPercent;
    }

    public Date getJvmStartTime() {
        return jvmStartTime;
    }

    public void setJvmStartTime(Date jvmStartTime) {
        this.jvmStartTime = jvmStartTime;
    }

    public long getJvmUpTime() {
        return jvmUpTime;
    }

    public void setJvmUpTime(long jvmUpTime) {
        this.jvmUpTime = jvmUpTime;
    }

    public String getJdkName() {
        return jdkName;
    }

    public void setJdkName(String jdkName) {
        this.jdkName = jdkName;
    }

    public String getJdkHome() {
        return jdkHome;
    }

    public void setJdkHome(String jdkHome) {
        this.jdkHome = jdkHome;
    }

    public String getJdkVersion() {
        return jdkVersion;
    }

    public void setJdkVersion(String jdkVersion) {
        this.jdkVersion = jdkVersion;
    }

    public int getNetReceiveDataCount() {
        return netReceiveDataCount;
    }

    public void setNetReceiveDataCount(int netReceiveDataCount) {
        this.netReceiveDataCount = netReceiveDataCount;
    }

    public int getNetSendDataCount() {
        return netSendDataCount;
    }

    public void setNetSendDataCount(int netSendDataCount) {
        this.netSendDataCount = netSendDataCount;
    }

    public int getNetReceiveKbCount() {
        return netReceiveKbCount;
    }

    public void setNetReceiveKbCount(int netReceiveKbCount) {
        this.netReceiveKbCount = netReceiveKbCount;
    }

    public int getNetSendKbCount() {
        return netSendKbCount;
    }

    public void setNetSendKbCount(int netSendKbCount) {
        this.netSendKbCount = netSendKbCount;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }
}
